//
//  NavViewController.m
//  PeitaMerchants
//
//  Created by apple on 17/8/22.
//  Copyright © 2017年 Facebook. All rights reserved.
//

#import "NavViewController.h"
#import "ChatViewController.h"

@interface NavViewController ()

@end

@implementation NavViewController

- (void)viewWillAppear:(BOOL)animated {
  
  [super viewWillAppear:animated];
  
  self.navigationController.navigationBarHidden = YES;
}

- (void)viewWillDisappear:(BOOL)animated {
  [super viewWillDisappear:animated];
  
  self.navigationController.navigationBarHidden = NO;
}

+(void)initialize
{
  // 1.设置导航栏主题
  [self setupBarButtonItemTheme];
  
}

+(void)setupBarButtonItemTheme
{
  //取出appearance对象
  UINavigationBar *navBar = [UINavigationBar appearance];
  
  navBar.shadowImage = [[UIImage alloc]init];
  
  navBar.backgroundColor = [UIColor whiteColor];
  [navBar setBackgroundImage:[UIImage imageNamed:@"nav"] forBarMetrics:UIBarMetricsDefault];
  
  // 设置标题属性
  NSMutableDictionary *textAttrs = [NSMutableDictionary dictionary];
  textAttrs[NSForegroundColorAttributeName] = [UIColor whiteColor];
  
  [navBar setTitleTextAttributes:textAttrs];
  
}


- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
  
  [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(openChat:) name:@"openChat" object:nil];
}

- (void)openChat:(NSNotification *)openChatNot {
  
  NSLog(@"收到了打开聊天界面");
  
  dispatch_async(dispatch_get_main_queue(), ^{
    
    NSDictionary *dict = [openChatNot object];
    ChatViewController *chatVC = [[ChatViewController alloc] init];
    chatVC.name = dict[@"userName"];
    chatVC.targetId = dict[@"userId"];
    if ([dict[@"status"] isEqualToNumber:@1]) {
      
      // 单聊
      chatVC.conversationType = ConversationType_PRIVATE;
    } else {
      
      // 群聊
      chatVC.conversationType = ConversationType_GROUP;
    }
    [self pushViewController:chatVC animated:YES];
  });
  
  
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
